<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>haveSameContents</title>
</head>

<body>
    <div>打开浏览器控制台查看结果</div>
    <script>
        const haveSameContents = (a, b) => {
            for (const v of new Set([...a, ...b])) {
                if (a.filter(e => e === v).length !== b.filter(e => e === v).length) {
                    return false;
                }
            }
            return true;
        };
        console.log(haveSameContents([1, 2, 4], [2, 4, 1]), haveSameContents([1, 2, 4], [2, 4]));
    </script>
</body>

</html>